﻿using System.Data.SqlServerCe;
using System.Text;

namespace Distribution.Data
{
    public class DDistribution
    {
        #region - Public methods -

        public static void ClearDatabase()
        {
            SqlCeConnection con = null;
            SqlCeDataAdapter da;
            StringBuilder query;
            try
            {
                con = Helper.GetConnection();
                
                query = new StringBuilder("Delete tb_NotesXMeters");
                da = new SqlCeDataAdapter(query.ToString(), con);
                da.SelectCommand.ExecuteNonQuery();

                query = new StringBuilder("Delete tb_Meters");
                da = new SqlCeDataAdapter(query.ToString(), con);
                da.SelectCommand.ExecuteNonQuery();

                query = new StringBuilder("Delete tb_PhasesXPoles");
                da = new SqlCeDataAdapter(query.ToString(), con);
                da.SelectCommand.ExecuteNonQuery();

                query = new StringBuilder("Delete tb_TopsXPoles");
                da = new SqlCeDataAdapter(query.ToString(), con);
                da.SelectCommand.ExecuteNonQuery();

                query = new StringBuilder("Delete tb_Pole_InspectionResult");
                da = new SqlCeDataAdapter(query.ToString(), con);
                da.SelectCommand.ExecuteNonQuery();

                query = new StringBuilder("Delete tb_PoleImages");
                da = new SqlCeDataAdapter(query.ToString(), con);
                da.SelectCommand.ExecuteNonQuery();

                query = new StringBuilder("Delete tb_PoleResults");
                da = new SqlCeDataAdapter(query.ToString(), con);
                da.SelectCommand.ExecuteNonQuery();

                query = new StringBuilder("Delete tb_Poles");
                da = new SqlCeDataAdapter(query.ToString(), con);
                da.SelectCommand.ExecuteNonQuery();

            }
            finally
            {
                if (con != null)
                    con.Close();
            }
        }

        #endregion
    }
}
